from typing import List


class Solution:
    def findDuplicates(self, nums: List[int]) -> List[int]:
        for i in range(len(nums)):
            while nums[i] != nums[nums[i] - 1]:
                nums[nums[i] - 1], nums[i] = nums[i], nums[nums[i] - 1]

        ##剩下和下表不相等的元素就是重复出现2次的元素
        return [num for i, num in enumerate(nums) if num - 1 != i]
